﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.PlayerFramework;
using System.IO;
using System.IO.IsolatedStorage;

namespace MyChannel
{
    public partial class ViewVideoPage : PhoneApplicationPage
    {
        string _type = "";
        public ViewVideoPage()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            NavigationContext.QueryString.TryGetValue("type", out _type);
            if (_type == "local")
            {
                using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(App.URL, FileMode.Open, FileAccess.Read))
                    {
                        media.SetSource(fileStream);
                        media.Volume = 1;
                        fileStream.Dispose();
                        fileStream.Close();
                    }
                }
            }
            else
            {
              media.Source = new Uri(App.URL, UriKind.Absolute);
              media.AutoLoad = true;
              media.AutoPlay = true;
            }
            media.Play();
            base.OnNavigatedTo(e);
        }
    }
}